﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HRM.BLL;
using HRM.DAL.DAO;

namespace HRM.UI.HRManagerUI.Profile
{
    public partial class EmpLeaveForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadReamainingLeave();
        }

        private void LoadReamainingLeave()
        {
            
            LeaveStatus leaveStatus = new LeaveStatus();
            LeaveStatusManager leaveStatusManager = new LeaveStatusManager();
            Code code=new Code();
            leaveStatus = leaveStatusManager.GetEmployeeLeaveStatus(code);
            code.CodeName = (string)Session["Code"];
            earnLeaveLbl.Text = leaveStatus.EarnLeave.ToString();
            casualLeaveLbl.Text = leaveStatus.CasualLeave.ToString();
            sickLeaveLbl.Text = leaveStatus.SickLeave.ToString();
            otherLbl.Text = leaveStatus.Others.ToString();
        }

        protected void BtnApplyNow(object sender, EventArgs e)
        {
            try
            {
                ApplicationManager applicationManager = new ApplicationManager();
                LeaveApplication application = new LeaveApplication();
                Employee employee = new Employee();

                DateTime today = DateTime.Now;
                string empcode = (string)Session["Code"];
                //string empcode = "hr-1001";
                Code code = new Code();
                code.CodeName = empcode;
                employee.EmpCode = code;
                application.Employee = employee;
                application.ApplyDate = today.ToShortDateString();
                application.StartDate =txtStartDate.Value;
                application.EndDate =txtEndDate.Value;
                application.TotalDays = Convert.ToInt32(txtTotalDays.Value);
                application.LeaveType = ddlLeaveType.Value;
                application.Reason = "NA";
                application.Subject = txtLeaveSubject.Value;
                application.Message = txtLeaveMessage.Value.Replace(char.ConvertFromUtf32(13), "<br/>"); 
                if (applicationManager.SendApplication(code, application))
                {
                    msgLebel.Text = "Successfully sent Leave Application";
                    msgLebel.ForeColor = Color.Green;
                }
                else
                {
                    msgLebel.Text = "Sorry,Not sent Leave Application";
                    msgLebel.ForeColor = Color.Red;
                }

            }
            catch (Exception ex)
            {

                msgLebel.ForeColor = Color.Red;
                msgLebel.Text = ex.Message;
            }

        }
    }
}